﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>教师管理</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav2.cshtml")
        <div class="container">
            <div class="row">
                <h1 class="topTitle-h1">康复治疗微课程网络学习平台<br><small>广州中医药大学康复治疗微课程网络学习平台</small></h1>
            </div>
        </div>
        @Html.Partial("~/Views/Share/PublicAdminNaviMenu.cshtml", 0)
        <div class="container mainwrap">
            <div class="row">
                <div class="col-xs-2">
                    <div class="dropdown theme-dropdown clearfix">
                        <a id="dropdownMenu1" href="#" role="button" class="sr-only dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                            <li class="active" role="presentation">
                                <a role="menuitem" tabindex="-1" href="javascript:void(0)">
                                    <span class="glyphicon glyphicon-user"></span> 教师列表
                                </a>
                            </li>
                            <li role="presentation" class="divider"></li>
                            <li role="presentation">
                                <a role="menuitem" tabindex="-1" href="@Url.Action("AddTeacher", "UserInfo")">
                                    <span class="glyphicon glyphicon-plus"></span> 新建教师
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="col-xs-10">
                    <div class="panel panel-default mainwrap-part">
                        <div class="panel-heading">
                            <h3 class="panel-title">
                                <ol class="breadcrumb">
                                    <li>教师用户管理</li>
                                    <li class="active">教师列表</li>
                                </ol>
                            </h3>
                        </div>
                        <div class="panel-body">
                            <div class="row">
                                <form class="form-horizontal" role="form">
                                    <div class="form-group clearfix">
                                        <label class="control-label col-xs-1">用户名:</label>
                                        <div class="col-xs-3">
                                            <input type="text" class="form-control input-md" id="Jaccount" placeholder="请输入用户名" />
                                        </div>
                                        <label class="control-label col-xs-1">姓名:</label>
                                        <div class="col-xs-3">
                                            <input type="text" class="form-control input-md" id="Jrealname" placeholder="请输入姓名" />
                                        </div>
                                        <div class="col-xs-2">
                                            <button type="button" id="JtecSearch" class="btn btn-success btn-md"><span class="glyphicon glyphicon-search"></span> 搜索 </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="row">
                                <table class="table table-bordered tb1 table-striped table-hover">
                                    <thead>
                                        <tr>
                                            <th width="15%">用户名</th>
                                            <th width="15%">姓名</th>
                                            <th width="30%">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="JgrpTbody">
                                    
                                    </tbody>
                                </table>
                            </div>
                            <div class="row clearfix well">
                                <div id="PagInfo" class="pull-left sum"></div>
                                <div class="clearfix pull-right">
                                    <ul id="PageTool" class="pagination"></ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 更改密码的弹框 -->
        <div class="modal fade" id="changePwModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">修改密码</h4>
              </div>
              <div class="modal-body">
                <div class="form-group">
                <label for="JcGrpName">输入密码：</label>
                <input type="text" class="form-control" id="Jcpw" placeholder="请输入新密码">
                </div>
                <div class="form-group">
                <label for="JcRemark">确认密码：</label>
                <input type="text" class="form-control" id="Jcpw2" placeholder="请再次输入密码">
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" id="JcSubmit" class="btn btn-info">确认修改</button>
              </div>
            </div>
          </div>
        </div>
        @Html.Partial("~/Views/Share/PublicFooter.cshtml")
        @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")
    <script>
        var account = $("#Jaccount"),
            realname = $("#Jrealname"),
            tecSearch = $("#JtecSearch"),
            _account = account.val(),
            _realname = realname.val(),
            page = 1,
            grpTbody = $("#JgrpTbody"),
            Jcpw = $("#Jcpw"),
            Jcpw2 = $("#Jcpw2"),
            changePwModal = $("#changePwModal");
        tecSearch.bind("click", function () {
            _account = account.val();
            _realname = realname.val();
            getList(page, _account, _realname);
        })
        function getList(pageNo, account, realname) {
            page = pageNo;
            _account = account;
            _realname = realname;
            $.easyPost("@Url.Action("SearchTeacher", "UserInfo")", {
                "PageNO": page, 
                "PageSize": 10,
                "Account": account ,
                "RealName": realname                
            }, function (data) {
                if (!data.result) {
                    showTips.open(data.message);
                    return;
                }
                if (data.rows.length > 0) {
                    var _row = data.rows,
                        _rowL = _row.length,
                        _html = '';
                    var options = {
                        totalPages: data.totalPage,
                        total: data.total,
                        currentPage: pageNo,
                        onPageClicked: function (event, originalEvent, type, page) {
                            getList(page, _account, _realname);
                        }
                    }
                    initialPaginator(options, "PageTool", "PagInfo");
                    for (var i = 0; i < _rowL; i++) {
                        var _grpInfo = _row[i];
                        _html += '<tr data-grpid=\"' + _grpInfo.Id.trim() + '\">' +
                                     '<td class=\"account\">' + _grpInfo.Account + '</td>' +
                                     '<td class=\"realName\">' + _grpInfo.RealName + '</td>' +
                                     '<td>' +
                                         '<a class=\"operate aChangePW\" href=\"javascript:void(0)\"><span class=\"glyphicon glyphicon-lock\"><\/span> 重置密码<\/a>' +
                                         //'<a class=\"operate\" href=\"javascript:void(0)\"><span class=\"glyphicon glyphicon-cog\"><\/span> 设置课程<\/a>' +
                                     '</td>' +
                                 '</tr>'
                    }
                    grpTbody.html(_html)
                } else {
                    var _html = '<tr><td colspan="3" align="center">暂无内容</td></tr>'
                    grpTbody.html(_html)
                }
            }, "json");
        }
        getList(page, _account, _realname);
        grpTbody.bind("click", function (e) {
            var _self = $(e.target);
            if (_self.hasClass("aChangePW") || _self.parent().hasClass("aChangePW")) {
                var _change = _self.hasClass("aChangePW") ? _self : _self.parent(),
                   _tr = _change.parent().parent(),
                   _ant = $(".account", _tr).html();
                changePwModal.attr("data-ant", _ant);
                changePwModal.modal("show");
                setTimeout(function () {
                    Jcpw.focus().select();
                }, 500)
            }
        })
        $("#JcSubmit").bind("click", function () {
            var _pw = Jcpw.val(),
                _pw2 = Jcpw2.val(),
                _ant = changePwModal.attr("data-ant");
            $.easyPost("@Url.Action("ResetTeacherPassword", "UserInfo")", { 
                "Account": _ant,
                "Password": _pw,
                "Password2": _pw2
            }, function (data) {
                if (data.result) {
                    showTips.open("修改成功！");
                    changePwModal.modal("hide")
                    getList(page, _account, _realname);
                    return;
                } else {
                    showTips.open(data.message)
                }
            }, "json")
        })
    </script>
</body>
</html>
